


import 'package:bt_tool/basic/bt_controller.dart';
import 'package:bt_tool/basic/bt_language_tool.dart';
import 'package:bt_tool/basic/bt_nav_tool.dart';
import 'package:bt_tool/widget/bt_base_btn_widget.dart';
import 'package:bt_tool/widget/bt_text_field.dart';
import 'package:bt_tool/widget/bt_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/tools/translate/translate_define.dart';
import 'package:get/get.dart';

import '../../../common/config/app_theme_color_config.dart';
import '../controller/translate_result_controller.dart';

class TranslateResultPage extends BTStatefulWidget{

  const TranslateResultPage({super.key,super.routerConfig});


  @override
  State<StatefulWidget> createState() {
    return TranslateResultState();
  }

}

class TranslateResultState extends BTState<TranslateResultPage>{

  final TranslateResultController controller = TranslateResultController();

  @override
  BTController btCtrl() {
    return controller;
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> headList = [];
    for(var key in controller.dataMap.keys){
      headList.add(GestureDetector(
        child: BTBtnTextWidget(
          text: controller.dataMap[key],
        ),
      ));
    }
    return Scaffold(
      appBar: BTNavTool.createAppBar(
        title: "翻译结果".btTrans,
        context: context,
        rightPadding: 10,
      ),
      body: Container(
        padding: const EdgeInsets.all(12),
        child: Column(
          children: [
            Obx((){
              List<Widget> headList = [];
              for(var key in controller.dataMap.keys){
                headList.add(GestureDetector(
                  child: BTBtnTextWidget(
                    text: TranslateDefine.baseLanguageMapReverse[key] ?? "",
                    bgColor: key == controller.selectKey.value ? AppThemeColor.mainColor : Colors.grey,
                    textColor: Colors.white,
                    alignment: Alignment.center,
                    onTap: (){
                      controller.changeKey(key);
                    },
                  ),
                ));
              }
              return Flex(
                direction: Axis.horizontal,
                spacing: 8,
                children: headList,
              );
            }),
            const SizedBox(height: 10,),
            Expanded(child: BTTextFieldWidget(
              btTextFieldController: controller.textFieldController,
              maxLine: 1000,
            )),
            const SizedBox(height: 10,),
            Row(
              children: [
                BTBtnTextWidget(
                  bgColor: AppThemeColor.mainColor,
                  text: "复制所有内容".btTrans,
                  textColor: Colors.white,
                  onTap: () => controller.copyClick(),
                  alignment: Alignment.center,
                ),
                const SizedBox(width: 10,),
                BTBtnTextWidget(
                  bgColor: AppThemeColor.mainColor,
                  text: "复制文字内容".btTrans,
                  textColor: Colors.white,
                  onTap: () => controller.copyTextClick(),
                  alignment: Alignment.center,
                ),
              ],
            )
          ],
        ),
      ),
    );
  }

}